package com.tianpengtech.common.util;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.plugin.activerecord.Page;

/*
 * JSON工具类
 */
public class JsonUtil {

    public static Map<String, Object> printSuccess(String msg) {

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", true);
        map.put("msg", msg);
        return map;
    }

    public static Map<String, Object> printError(String msg) {

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", false);
        map.put("msg", msg);
        return map;
    }

    public static Map<String, Object> printObject(Object obj) {

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", true);
        map.put("data", obj);
        return map;
    }

    public static Map<String, Object> printSuccessJsonForUpload(String value) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("error", 0);
        result.put("url", value);
        return result;

    }

    public static Map<String, Object> printErrorJsonForUpload(String value) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("error", 1);
        result.put("message", value);
        return result;
    }

    public static Map<String, Object> printJsonForHPlus(int draw, Page<?> models) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("draw", draw);
        result.put("recordsTotal", models.getTotalRow());
        result.put("recordsFiltered", models.getTotalRow());
        result.put("data", models.getList());
        return result;
    }

}
